﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using IFRS.DataAccess.DAL;
using IFRS.Models;
using IFRS.Web;
using vsm.CustomControl;

public partial class IFRS_WIN31_GL_LOT_2E : PageBase
{
    #region === Property ===

    public string SrciptSetValueGlAccountGl = string.Empty;

    #endregion

    #region === Event ===

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewMenu();
            BindControl();
            BindData();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");

        SetValueGlAccountGl();
    }

    protected void btnSAVE_Click(object sender, EventArgs e)
    {
        if (!CheckDuplicateGl(form_control))
            SaveData();
    }
    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN31_1S.aspx");
    }

    #endregion

    #region === Method ===

    private void ViewMenu()
    {
        MenuTitleBar = Resources.ifrsMenu.WIN31_GL_LOT_2E;
    }
    private void BindControl()
    {
        btnSAVE.ValidationGroup = "Master";

        SetButtonPopup(btnGLAccount, txtGLAccount);
        SetButtonPopup(btnGL_ADJ_INT_INC_PL, txtGL_ADJ_INT_INC_PL);
        SetButtonPopup(btnGL_ADJ_FV_BS, txtGL_ADJ_FV_BS);
        SetButtonPopup(btnGL_ADJ_INT_INC_ELCLS_PL, txtGL_ADJ_INT_INC_ELCLS_PL);
        SetButtonPopup(btnGL_ADJ_CST_BS, txtGL_ADJ_CST_BS);
        SetButtonPopup(btnGL_REV_CST_PL, txtGL_REV_CST_PL);
        SetButtonPopup(btnGL_ADJ_FEE_BS, txtGL_ADJ_FEE_BS);
        SetButtonPopup(btnGL_REV_FEE_PL, txtGL_REV_FEE_PL);
        SetButtonPopup(btnGL_SUBSEQ_ADJ_CST_BS, txtGL_SUBSEQ_ADJ_CST_BS);
        SetButtonPopup(btnGL_SUBSEQ_ADJ_FEE_BS, txtGL_SUBSEQ_ADJ_FEE_BS);
        SetButtonPopup(btnGL_IMP_LOSS_PL, txtGL_IMP_LOSS_PL);
        SetButtonPopup(btnGL_ALLW_BAD_DEBT_PL, txtGL_ALLW_BAD_DEBT_PL);
        SetButtonPopup(btnGL_WOFF_ADJ_FV_BS, txtGL_WOFF_ADJ_FV_BS);
        SetButtonPopup(btnGL_WOFF_ADJ_FEE_BS, txtGL_WOFF_ADJ_FEE_BS);
        SetButtonPopup(btnGL_WOFF_ADJ_CST_BS, txtGL_WOFF_ADJ_CST_BS);
        SetButtonPopup(btnGL_DAY1_FV_LOSS_PL, txtGL_DAY1_FV_LOSS_PL);
        SetButtonPopup(btnGL_DAY1_ADJ_FV_BS, txtGL_DAY1_ADJ_FV_BS);
        SetButtonPopup(btnGL_WOFF_INT_DISC_LN, txtGL_WOFF_INT_DISC_LN);
        SetButtonPopup(btnGL_DAY1_DEF_EXP_STAFF_BS, txtGL_DAY1_DEF_EXP_STAFF_BS);
        SetButtonPopup(btnGL_AMC_EMP_CST_PL, txtGL_AMC_EMP_CST_PL);
        SetButtonPopup(btnGL_AMC_DEF_EXP_STAFF_BS, txtGL_AMC_DEF_EXP_STAFF_BS);
        SetButtonPopup(btnGL_SUBSIDY_INT_REC_BS, txtGL_SUBSIDY_INT_REC_BS);
        SetButtonPopup(btnGL_SUBSIDY_INT_INC_PL, txtGL_SUBSIDY_INT_INC_PL);

        SetTextboxAutoComplete(hddGLAccount_ID, txtGLAccount, txtGLAccountName);
        SetTextboxAutoComplete(hddGL_ADJ_INT_INC_PL_ID, txtGL_ADJ_INT_INC_PL, txtGL_ADJ_INT_INC_PL_NAME);
        SetTextboxAutoComplete(hddGL_ADJ_FV_BS_ID, txtGL_ADJ_FV_BS, txtGL_ADJ_FV_BS_NAME);
        SetTextboxAutoComplete(hddGL_ADJ_INT_INC_ELCLS_PL_ID, txtGL_ADJ_INT_INC_ELCLS_PL, txtGL_ADJ_INT_INC_ELCLS_PL_NAME);
        SetTextboxAutoComplete(hddGL_ADJ_CST_BS_ID, txtGL_ADJ_CST_BS, txtGL_ADJ_CST_BS_NAME);
        SetTextboxAutoComplete(hddGL_REV_CST_PL_ID, txtGL_REV_CST_PL, txtGL_REV_CST_PL_NAME);
        SetTextboxAutoComplete(hddGL_ADJ_FEE_BS_ID, txtGL_ADJ_FEE_BS, txtGL_ADJ_FEE_BS_NAME);
        SetTextboxAutoComplete(hddGL_REV_FEE_PL_ID, txtGL_REV_FEE_PL, txtGL_REV_FEE_PL_NAME);
        SetTextboxAutoComplete(hddGL_SUBSEQ_ADJ_CST_BS_ID, txtGL_SUBSEQ_ADJ_CST_BS, txtGL_SUBSEQ_ADJ_CST_BS_NAME);
        SetTextboxAutoComplete(hddGL_SUBSEQ_ADJ_FEE_BS_ID, txtGL_SUBSEQ_ADJ_FEE_BS, txtGL_SUBSEQ_ADJ_FEE_BS_NAME);
        SetTextboxAutoComplete(hddGL_IMP_LOSS_PL_ID, txtGL_IMP_LOSS_PL, txtGL_IMP_LOSS_PL_NAME);
        SetTextboxAutoComplete(hddGL_ALLW_BAD_DEBT_PL_ID, txtGL_ALLW_BAD_DEBT_PL, txtGL_ALLW_BAD_DEBT_PL_NAME);
        SetTextboxAutoComplete(hddGL_WOFF_ADJ_FV_BS_ID, txtGL_WOFF_ADJ_FV_BS, txtGL_WOFF_ADJ_FV_BS_NAME);
        SetTextboxAutoComplete(hddGL_WOFF_ADJ_FEE_BS_ID, txtGL_WOFF_ADJ_FEE_BS, txtGL_WOFF_ADJ_FEE_BS_NAME);
        SetTextboxAutoComplete(hddGL_WOFF_ADJ_CST_BS_ID, txtGL_WOFF_ADJ_CST_BS, txtGL_WOFF_ADJ_CST_BS_NAME);
        SetTextboxAutoComplete(hddGL_DAY1_FV_LOSS_PL_ID, txtGL_DAY1_FV_LOSS_PL, txtGL_DAY1_FV_LOSS_PL_NAME);
        SetTextboxAutoComplete(hddGL_DAY1_ADJ_FV_BS_ID, txtGL_DAY1_ADJ_FV_BS, txtGL_DAY1_ADJ_FV_BS_NAME);
        SetTextboxAutoComplete(hddGL_WOFF_INT_DISC_LN_ID, txtGL_WOFF_INT_DISC_LN, txtGL_WOFF_INT_DISC_LN_NAME);
        SetTextboxAutoComplete(hddGL_DAY1_DEF_EXP_STAFF_BS_ID, txtGL_DAY1_DEF_EXP_STAFF_BS, txtGL_DAY1_DEF_EXP_STAFF_BS_NAME);
        SetTextboxAutoComplete(hddGL_AMC_EMP_CST_PL_ID, txtGL_AMC_EMP_CST_PL, txtGL_AMC_EMP_CST_PL_NAME);
        SetTextboxAutoComplete(hddGL_AMC_DEF_EXP_STAFF_BS_ID, txtGL_AMC_DEF_EXP_STAFF_BS, txtGL_AMC_DEF_EXP_STAFF_BS_NAME);
        SetTextboxAutoComplete(hddGL_SUBSIDY_INT_REC_BS_ID, txtGL_SUBSIDY_INT_REC_BS, txtGL_SUBSIDY_INT_REC_BS_NAME);
        SetTextboxAutoComplete(hddGL_SUBSIDY_INT_INC_PL_ID, txtGL_SUBSIDY_INT_INC_PL, txtGL_SUBSIDY_INT_INC_PL_NAME);

        reqGLAccount.SetRequiredField(lblGLAccount, txtGLAccount, btnSAVE);

        txtGLGroup.Text = Resources.ifrsField.GL_LOT;
    }
    private void BindData()
    {
        if (Convert.ToString(Request.QueryString["id"]) != string.Empty)
        {

            var id = Convert.ToInt32(Request.QueryString["id"]);
            var dt = new SPR_GLACCOUNTPOSTING().SEARCH_BYID(id);
            if (dt != null && dt.Rows.Count > 0)
            {
                var list = new List<GLAccountPosting>();
                ConvertHelper.ConvertDataTableToObject(dt, list);

                hddGLGroupID.Value = list[0].GLGroupID.AsString();
                txtGLGroup.Text = list[0].GLGroup_NAME;

                hddGLAccount_ID.Value = list[0].GLAccountID.AsString();
                hddGL_ADJ_INT_INC_PL_ID.Value = list[0].GL_ADJ_INT_INC_PL_ID.AsString();
                hddGL_ADJ_FV_BS_ID.Value = list[0].GL_ADJ_FV_BS_ID.AsString();
                hddGL_ADJ_INT_INC_ELCLS_PL_ID.Value = list[0].GL_ADJ_INT_INC_ELCLS_PL_ID.AsString();
                hddGL_ADJ_CST_BS_ID.Value = list[0].GL_ADJ_CST_BS_ID.AsString();
                hddGL_REV_CST_PL_ID.Value = list[0].GL_REV_CST_PL_ID.AsString();
                hddGL_ADJ_FEE_BS_ID.Value = list[0].GL_ADJ_FEE_BS_ID.AsString();
                hddGL_REV_FEE_PL_ID.Value = list[0].GL_REV_FEE_PL_ID.AsString();
                hddGL_SUBSEQ_ADJ_CST_BS_ID.Value = list[0].GL_SUBSEQ_ADJ_CST_BS_ID.AsString();
                hddGL_SUBSEQ_ADJ_FEE_BS_ID.Value = list[0].GL_SUBSEQ_ADJ_FEE_BS_ID.AsString();
                hddGL_IMP_LOSS_PL_ID.Value = list[0].GL_IMP_LOSS_PL_ID.AsString();
                hddGL_ALLW_BAD_DEBT_PL_ID.Value = list[0].GL_ALLW_BAD_DEBT_PL_ID.AsString();
                hddGL_WOFF_ADJ_FV_BS_ID.Value = list[0].GL_WOFF_ADJ_FV_BS_ID.AsString();
                hddGL_WOFF_ADJ_FEE_BS_ID.Value = list[0].GL_WOFF_ADJ_FEE_BS_ID.AsString();
                hddGL_WOFF_ADJ_CST_BS_ID.Value = list[0].GL_WOFF_ADJ_CST_BS_ID.AsString();
                hddGL_DAY1_FV_LOSS_PL_ID.Value = list[0].GL_DAY1_FV_LOSS_PL_ID.AsString();
                hddGL_DAY1_ADJ_FV_BS_ID.Value = list[0].GL_DAY1_ADJ_FV_BS_ID.AsString();
                hddGL_WOFF_INT_DISC_LN_ID.Value = list[0].GL_WOFF_INT_DISC_LN_ID.AsString();
                hddGL_DAY1_DEF_EXP_STAFF_BS_ID.Value = list[0].GL_DAY1_DEF_EXP_STAFF_BS_ID.AsString();
                hddGL_AMC_EMP_CST_PL_ID.Value = list[0].GL_AMC_EMP_CST_PL_ID.AsString();
                hddGL_AMC_DEF_EXP_STAFF_BS_ID.Value = list[0].GL_AMC_DEF_EXP_STAFF_BS_ID.AsString();
                hddGL_SUBSIDY_INT_REC_BS_ID.Value = list[0].GL_SUBSIDY_INT_REC_BS_ID.AsString();
                hddGL_SUBSIDY_INT_INC_PL_ID.Value = list[0].GL_SUBSIDY_INT_INC_PL_ID.AsString();

                txtGLAccount.Text = list[0].GLAccount_CODE;
                txtGL_ADJ_INT_INC_PL.Text = list[0].GL_ADJ_INT_INC_PL_CODE;
                txtGL_ADJ_FV_BS.Text = list[0].GL_ADJ_FV_BS_CODE;
                txtGL_ADJ_INT_INC_ELCLS_PL.Text = list[0].GL_ADJ_INT_INC_ELCLS_PL_CODE;
                txtGL_ADJ_CST_BS.Text = list[0].GL_ADJ_CST_BS_CODE;
                txtGL_REV_CST_PL.Text = list[0].GL_REV_CST_PL_CODE;
                txtGL_ADJ_FEE_BS.Text = list[0].GL_ADJ_FEE_BS_CODE;
                txtGL_REV_FEE_PL.Text = list[0].GL_REV_FEE_PL_CODE;
                txtGL_SUBSEQ_ADJ_CST_BS.Text = list[0].GL_SUBSEQ_ADJ_CST_BS_CODE;
                txtGL_SUBSEQ_ADJ_FEE_BS.Text = list[0].GL_SUBSEQ_ADJ_FEE_BS_CODE;
                txtGL_IMP_LOSS_PL.Text = list[0].GL_IMP_LOSS_PL_CODE;
                txtGL_ALLW_BAD_DEBT_PL.Text = list[0].GL_ALLW_BAD_DEBT_PL_CODE;
                txtGL_WOFF_ADJ_FV_BS.Text = list[0].GL_WOFF_ADJ_FV_BS_CODE;
                txtGL_WOFF_ADJ_FEE_BS.Text = list[0].GL_WOFF_ADJ_FEE_BS_CODE;
                txtGL_WOFF_ADJ_CST_BS.Text = list[0].GL_WOFF_ADJ_CST_BS_CODE;
                txtGL_DAY1_FV_LOSS_PL.Text = list[0].GL_DAY1_FV_LOSS_PL_CODE;
                txtGL_DAY1_ADJ_FV_BS.Text = list[0].GL_DAY1_ADJ_FV_BS_CODE;
                txtGL_WOFF_INT_DISC_LN.Text = list[0].GL_WOFF_INT_DISC_LN_CODE;
                txtGL_DAY1_DEF_EXP_STAFF_BS.Text = list[0].GL_DAY1_DEF_EXP_STAFF_BS_CODE;
                txtGL_AMC_EMP_CST_PL.Text = list[0].GL_AMC_EMP_CST_PL_CODE;
                txtGL_AMC_DEF_EXP_STAFF_BS.Text = list[0].GL_AMC_DEF_EXP_STAFF_BS_CODE;
                txtGL_SUBSIDY_INT_REC_BS.Text = list[0].GL_SUBSIDY_INT_REC_BS_CODE;
                txtGL_SUBSIDY_INT_INC_PL.Text = list[0].GL_SUBSIDY_INT_INC_PL_CODE;

                txtGLAccountName.Text = list[0].GLAccount_NAME;
                txtGL_ADJ_INT_INC_PL_NAME.Text = list[0].GL_ADJ_INT_INC_PL_NAME;
                txtGL_ADJ_FV_BS_NAME.Text = list[0].GL_ADJ_FV_BS_NAME;
                txtGL_ADJ_INT_INC_ELCLS_PL_NAME.Text = list[0].GL_ADJ_INT_INC_ELCLS_PL_NAME;
                txtGL_ADJ_CST_BS_NAME.Text = list[0].GL_ADJ_CST_BS_NAME;
                txtGL_REV_CST_PL_NAME.Text = list[0].GL_REV_CST_PL_NAME;
                txtGL_ADJ_FEE_BS_NAME.Text = list[0].GL_ADJ_FEE_BS_NAME;
                txtGL_REV_FEE_PL_NAME.Text = list[0].GL_REV_FEE_PL_NAME;
                txtGL_SUBSEQ_ADJ_CST_BS_NAME.Text = list[0].GL_SUBSEQ_ADJ_CST_BS_NAME;
                txtGL_SUBSEQ_ADJ_FEE_BS_NAME.Text = list[0].GL_SUBSEQ_ADJ_FEE_BS_NAME;
                txtGL_IMP_LOSS_PL_NAME.Text = list[0].GL_IMP_LOSS_PL_NAME;
                txtGL_ALLW_BAD_DEBT_PL_NAME.Text = list[0].GL_ALLW_BAD_DEBT_PL_NAME;
                txtGL_WOFF_ADJ_FV_BS_NAME.Text = list[0].GL_WOFF_ADJ_FV_BS_NAME;
                txtGL_WOFF_ADJ_FEE_BS_NAME.Text = list[0].GL_WOFF_ADJ_FEE_BS_NAME;
                txtGL_WOFF_ADJ_CST_BS_NAME.Text = list[0].GL_WOFF_ADJ_CST_BS_NAME;
                txtGL_DAY1_FV_LOSS_PL_NAME.Text = list[0].GL_DAY1_FV_LOSS_PL_NAME;
                txtGL_DAY1_ADJ_FV_BS_NAME.Text = list[0].GL_DAY1_ADJ_FV_BS_NAME;
                txtGL_WOFF_INT_DISC_LN_NAME.Text = list[0].GL_WOFF_INT_DISC_LN_NAME;
                txtGL_DAY1_DEF_EXP_STAFF_BS_NAME.Text = list[0].GL_DAY1_DEF_EXP_STAFF_BS_NAME;
                txtGL_AMC_EMP_CST_PL_NAME.Text = list[0].GL_AMC_EMP_CST_PL_NAME;
                txtGL_AMC_DEF_EXP_STAFF_BS_NAME.Text = list[0].GL_AMC_DEF_EXP_STAFF_BS_NAME;
                txtGL_SUBSIDY_INT_REC_BS_NAME.Text = list[0].GL_SUBSIDY_INT_REC_BS_NAME;
                txtGL_SUBSIDY_INT_INC_PL_NAME.Text = list[0].GL_SUBSIDY_INT_INC_PL_NAME;
            }
        }
    }
    private void SaveData()
    {
        if (!Page.IsValid) return;

        var dal = new SPR_GLACCOUNTPOSTING();
        var models = new GLAccountPosting();

        models.GLAccountPostingID = Convert.ToInt32(Request.QueryString["id"]);

        models.GLGroupID = hddGLGroupID.Value.AsInt32();
        models.GLAccountID = hddGLAccount_ID.Value.AsInt32();

        models.GL_ADJ_INT_INC_PL_ID = hddGL_ADJ_INT_INC_PL_ID.Value.AsIntIsnull();
        models.GL_ADJ_FV_BS_ID = hddGL_ADJ_FV_BS_ID.Value.AsIntIsnull();
        models.GL_ADJ_INT_INC_ELCLS_PL_ID = hddGL_ADJ_INT_INC_ELCLS_PL_ID.Value.AsIntIsnull();
        models.GL_ADJ_CST_BS_ID = hddGL_ADJ_CST_BS_ID.Value.AsIntIsnull();
        models.GL_REV_CST_PL_ID = hddGL_REV_CST_PL_ID.Value.AsIntIsnull();
        models.GL_ADJ_FEE_BS_ID = hddGL_ADJ_FEE_BS_ID.Value.AsIntIsnull();
        models.GL_REV_FEE_PL_ID = hddGL_REV_FEE_PL_ID.Value.AsIntIsnull();
        models.GL_SUBSEQ_ADJ_CST_BS_ID = hddGL_SUBSEQ_ADJ_CST_BS_ID.Value.AsIntIsnull();
        models.GL_SUBSEQ_ADJ_FEE_BS_ID = hddGL_SUBSEQ_ADJ_FEE_BS_ID.Value.AsIntIsnull();
        models.GL_IMP_LOSS_PL_ID = hddGL_IMP_LOSS_PL_ID.Value.AsIntIsnull();
        models.GL_ALLW_BAD_DEBT_PL_ID = hddGL_ALLW_BAD_DEBT_PL_ID.Value.AsIntIsnull();
        models.GL_WOFF_ADJ_FV_BS_ID = hddGL_WOFF_ADJ_FV_BS_ID.Value.AsIntIsnull();
        models.GL_WOFF_ADJ_FEE_BS_ID = hddGL_WOFF_ADJ_FEE_BS_ID.Value.AsIntIsnull();
        models.GL_WOFF_ADJ_CST_BS_ID = hddGL_WOFF_ADJ_CST_BS_ID.Value.AsIntIsnull();
        models.GL_DAY1_FV_LOSS_PL_ID = hddGL_DAY1_FV_LOSS_PL_ID.Value.AsIntIsnull();
        models.GL_DAY1_ADJ_FV_BS_ID = hddGL_DAY1_ADJ_FV_BS_ID.Value.AsIntIsnull();
        models.GL_WOFF_INT_DISC_LN_ID = hddGL_WOFF_INT_DISC_LN_ID.Value.AsIntIsnull();
        models.GL_DAY1_DEF_EXP_STAFF_BS_ID = hddGL_DAY1_DEF_EXP_STAFF_BS_ID.Value.AsIntIsnull();
        models.GL_AMC_EMP_CST_PL_ID = hddGL_AMC_EMP_CST_PL_ID.Value.AsIntIsnull();
        models.GL_AMC_DEF_EXP_STAFF_BS_ID = hddGL_AMC_DEF_EXP_STAFF_BS_ID.Value.AsIntIsnull();
        models.GL_SUBSIDY_INT_REC_BS_ID = hddGL_SUBSIDY_INT_REC_BS_ID.Value.AsIntIsnull();
        models.GL_SUBSIDY_INT_INC_PL_ID = hddGL_SUBSIDY_INT_INC_PL_ID.Value.AsIntIsnull();

        models.SetStandardField();

        var result = dal.UPDATE(models);
        if (result > 0)
            JS_Alert(Resources.ifrsResource.SaveData, ResolveUrl(string.Format("~/IFRS/WIN31_GL_LOT_2E.aspx?&id={0}", models.GLAccountPostingID)));
        else // Duplicate
            Utility.AlertMessage(Page,result == -1 ? Resources.ifrsResource.Duplicate : Resources.ifrsResource.CanNotSaveData);
    }

    private void SetTextboxAutoComplete(HiddenField hddField, TextboxAutoComplete textboxAutoComplete, TextBox textBox)
    {
        textboxAutoComplete.AddControl(hddField.ClientID);
        textboxAutoComplete.AddControl(textboxAutoComplete.ClientID);
        textboxAutoComplete.AddControl(textBox.ClientID);
        textboxAutoComplete.ControlSearch = textboxAutoComplete.ClientID;
        textboxAutoComplete.SearchKey = "GLAccount_oGLAccountCode_oGLAccountName_GL";
    }

    private void SetButtonPopup(Button button, TextboxAutoComplete textboxAutoComplete)
    {
        button.Attributes.Add("onClick", "return popWindow('" + ResolveUrl("~/PopupPages/GLAccount_GL.aspx?&PopUp=" + textboxAutoComplete.ID) + "','700','550');");
    }

    private string Gen_Srcipt_SetValueGLAccount_GL(HiddenField hddField, TextboxAutoComplete textboxAutoComplete, TextBox textBox)
    {
        var script = string.Empty;
        script += String.Format("if('{0}' == Value4)", textboxAutoComplete.ID);
        script += " {";
        script += String.Format("document.getElementById('{0}').value = Value1;", hddField.ClientID);
        script += String.Format("document.getElementById('{0}').value = Value2;", textboxAutoComplete.ClientID);
        script += String.Format("document.getElementById('{0}').value = Value3;", textBox.ClientID);
        script += " }";
        return script;
    }

    private void SetValueGlAccountGl()
    {
        SrciptSetValueGlAccountGl += "<script type='text/javascript'>window.SetValueGLAccount_GL = function (Value1, Value2, Value3, Value4) {  ";
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGLAccount_ID, txtGLAccount, txtGLAccountName);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_ADJ_INT_INC_PL_ID, txtGL_ADJ_INT_INC_PL, txtGL_ADJ_INT_INC_PL_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_ADJ_FV_BS_ID, txtGL_ADJ_FV_BS, txtGL_ADJ_FV_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_ADJ_INT_INC_ELCLS_PL_ID, txtGL_ADJ_INT_INC_ELCLS_PL, txtGL_ADJ_INT_INC_ELCLS_PL_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_ADJ_CST_BS_ID, txtGL_ADJ_CST_BS, txtGL_ADJ_CST_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_REV_CST_PL_ID, txtGL_REV_CST_PL, txtGL_REV_CST_PL_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_ADJ_FEE_BS_ID, txtGL_ADJ_FEE_BS, txtGL_ADJ_FEE_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_REV_FEE_PL_ID, txtGL_REV_FEE_PL, txtGL_REV_FEE_PL_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_SUBSEQ_ADJ_CST_BS_ID, txtGL_SUBSEQ_ADJ_CST_BS, txtGL_SUBSEQ_ADJ_CST_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_SUBSEQ_ADJ_FEE_BS_ID, txtGL_SUBSEQ_ADJ_FEE_BS, txtGL_SUBSEQ_ADJ_FEE_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_IMP_LOSS_PL_ID, txtGL_IMP_LOSS_PL, txtGL_IMP_LOSS_PL_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_ALLW_BAD_DEBT_PL_ID, txtGL_ALLW_BAD_DEBT_PL, txtGL_ALLW_BAD_DEBT_PL_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_WOFF_ADJ_FV_BS_ID, txtGL_WOFF_ADJ_FV_BS, txtGL_WOFF_ADJ_FV_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_WOFF_ADJ_FEE_BS_ID, txtGL_WOFF_ADJ_FEE_BS, txtGL_WOFF_ADJ_FEE_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_WOFF_ADJ_CST_BS_ID, txtGL_WOFF_ADJ_CST_BS, txtGL_WOFF_ADJ_CST_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_DAY1_FV_LOSS_PL_ID, txtGL_DAY1_FV_LOSS_PL, txtGL_DAY1_FV_LOSS_PL_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_DAY1_ADJ_FV_BS_ID, txtGL_DAY1_ADJ_FV_BS, txtGL_DAY1_ADJ_FV_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_WOFF_INT_DISC_LN_ID, txtGL_WOFF_INT_DISC_LN, txtGL_WOFF_INT_DISC_LN_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_DAY1_DEF_EXP_STAFF_BS_ID, txtGL_DAY1_DEF_EXP_STAFF_BS, txtGL_DAY1_DEF_EXP_STAFF_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_AMC_EMP_CST_PL_ID, txtGL_AMC_EMP_CST_PL, txtGL_AMC_EMP_CST_PL_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_AMC_DEF_EXP_STAFF_BS_ID, txtGL_AMC_DEF_EXP_STAFF_BS, txtGL_AMC_DEF_EXP_STAFF_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_SUBSIDY_INT_REC_BS_ID, txtGL_SUBSIDY_INT_REC_BS, txtGL_SUBSIDY_INT_REC_BS_NAME);
        SrciptSetValueGlAccountGl += Gen_Srcipt_SetValueGLAccount_GL(hddGL_SUBSIDY_INT_INC_PL_ID, txtGL_SUBSIDY_INT_INC_PL, txtGL_SUBSIDY_INT_INC_PL_NAME);
        SrciptSetValueGlAccountGl += " }</script>";
    }

    private bool CheckDuplicateGl(PlaceHolder plc)
    {
        var alertTextDetail = string.Empty;
        var lstHidden = new List<HiddenGl>();
        foreach (Control ctrl in plc.Controls)
        {
            if (ctrl is HiddenField)
            {
                if (((HiddenField)ctrl).Value != string.Empty)
                    lstHidden.Add(new HiddenGl { HiddenId = ctrl.ID, Value = ((HiddenField)ctrl).Value });
            }
        }

        for (var i = 0; i < lstHidden.Count; i++)
        {
            var tmp = string.Empty;
            var dupValue = lstHidden[i].Value; // ค่า Value ที่เช็คซ้ำ
            var lst = lstHidden.Where(x => x.Value == dupValue && x.Value != "" && x.HiddenId != lstHidden[i].HiddenId).ToList();
            foreach (var row in lst)
            {
                //var lblControl = (Label)plc.FindControl("lbl" + row.HiddenId.Substring(3));
                var lblId = "lbl" + row.HiddenId.Substring(3);
                lblId = lblId.Remove(lblId.Length - 3, 3);
                var lblControl = (Label)plc.FindControl(lblId);
                tmp += lblControl.Text + ", ";
            }
            if (lst.Count != 0 && i < lstHidden.Count - 1)
            {
                //alertTextDetail += "- " + ((Label)plc.FindControl("lbl" + lstHidden[i].HiddenId.Substring(3))).Text + ", ";
                var lblId = "lbl" + lstHidden[i].HiddenId.Substring(3);
                lblId = lblId.Remove(lblId.Length - 3, 3);
                alertTextDetail += "- " + ((Label)plc.FindControl(lblId)).Text + ", ";
                alertTextDetail += tmp.Substring(0, tmp.Length - 2) + "\\n";
            }

            for (int j = 0; j < lstHidden.Count; j++)
            {
                // Clear ค่า Value ใน List<HiddenGL> ที่ซ้ำ
                if (lstHidden[j].Value == dupValue)
                    lstHidden[j].Value = string.Empty;
            }
        }

        if (alertTextDetail == "")
        {
            return false;
        }

        var scriptAlert = Resources.ifrsResource.Alert_TextHeaderGL + alertTextDetail;
        Utility.AlertMessage(Page, scriptAlert);
        return true;
    }
    public class HiddenGl
    {
        public string HiddenId { get; set; }
        public string Value { get; set; }
    }

    #endregion
}